import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { VersioningType } from '@nestjs/common';
import { generateDocument } from './common/api.docs';
import { TransformInterceptor } from './common/interceptors/transform.interceptor';
import { HttpExceptionFilter } from './common/exceptions/http.filter';
import { AllExceptionsFilter } from './common/exceptions/base.filter';
async function bootstrap() {
  const app = await NestFactory.create(AppModule, {
    cors: true, //支持跨域
  });
  //异常过滤器
  app.useGlobalFilters(new AllExceptionsFilter(), new HttpExceptionFilter());
  // 全局拦截器
  app.useGlobalInterceptors(new TransformInterceptor());

  // 设置全局路由前缀为 /api
  app.setGlobalPrefix('api');
  //版本号
  app.enableVersioning({
    type: VersioningType.URI,
  });
  // swigger接口文档
  generateDocument(app);
  await app.listen(process.env.PORT ?? 8001);
}
bootstrap();
